import App from './App'

import core from './xilu/core.js';

import util from './xilu/util.js';
import chatIM from './xilu/websocket.js';
import {
	hexToRgba
} from './xilu/colorConvert.js';
// 挂载
Vue.prototype.$core = core; //core
Vue.prototype.$util = util; //util
Vue.prototype.$chatIM = chatIM; //util


/**
 * @param search
 * @param replace
 * @param str
 */
Vue.prototype.strReplace = function(search, replace, str) {
	if (!str)
		return '';
	search = new RegExp(search, 'g');
	return str.replace(search, replace);
};

Vue.prototype.cdnurl = function(url, default_file = '', watermark = false) {
	if (url && url.indexOf("http") != 0 && url.indexOf("https") != 0) {
		url = getApp().globalData.storageBaseUri + url
		return url
	} else if (url) {
		return url
	} else if (default_file) {
		return default_file;
	} else {
		return getApp().globalData.config.logo
	}
}
Vue.prototype.formatDatetime = function(date, fmt) { //author: meizz
	if (!date) {
		return "";
	}
	if (!(date instanceof Date)) {
		if (/^\d+$/.test(date)) {
			date = (date + "").length > 10 ? date : date * 1000;
			date = new Date(parseInt(date));
		} else {
			date = new Date(date.replace(/-/g, '/'));
		}
	}
	var o = {
		"m+": date.getMonth() + 1, //月份
		"d+": date.getDate(), //日
		"h+": date.getHours(), //小时
		"i+": date.getMinutes(), //分
		"s+": date.getSeconds(), //秒
		"q+": Math.floor((date.getMonth() + 3) / 3), //季度
		"S": date.getMilliseconds() //毫秒
	};
	var yearMatch = fmt.match(/(y+)/);
	if (yearMatch) {
		fmt = fmt.replace(yearMatch[0], (date.getFullYear() + "").substr(4 - yearMatch[0].length));
	}
	for (var k in o) {
		var match = fmt.match(new RegExp("(" + k + ")"));
		if (match)
			fmt = fmt.replace(match[0], (match[0].length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k])
				.length)));
	}
	return fmt;
};

Vue.prototype.inArray = function(value, array) {
	return array ? array.indexOf(value) >= 0 : false;
};
Vue.prototype.getListItemById = function(list, id) {
	if (!list || id == undefined || id === '')
		return null;
	for (var i = 0; i < list.length; i++) {
		if (list[i].id == id) {
			return list[i];
		}
	}
	return null;
};
Vue.prototype.getListItemAttrById = function(list, id, attrName, defaultValue = '') {
	var item = this.getListItemById(list, id);
	if (item && item[attrName]) {
		return item[attrName];
	}
	return defaultValue;
};
Vue.prototype.primarySize = function() {
	const primarySize = 'primary_' + getApp()?.globalData?.primary;
	return primarySize;
};
Vue.prototype.primaryColor = function() {
	let primarySize = '#2A79F2';
	if (getApp()?.globalData?.primary == 'blue') {
		primarySize = '#2A79F2';
	} else if (getApp()?.globalData?.primary == 'orange') {
		primarySize = '#ff7100'
	}
	return primarySize;
};
Vue.prototype.primaryColorOpacity1 = function() {
	const primarySize = hexToRgba(getApp()?.globalData?.color, 0.1);
	return primarySize;
};
Vue.prototype.primaryColorOpacity5 = function() {
	const primarySize = hexToRgba(getApp()?.globalData?.color, 0.5);
	return primarySize;
};
Vue.prototype.iconPath = function(url) {
	const primary = getApp()?.globalData?.primary;
	return '/static/' + primary + '/' + url;
}
// 全局混入：主题管理

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)
import Footer from '@/components/footer/footer.vue';
Vue.component('Footer', Footer)
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif